/*
 * Powered By dico
 * Since 2017 - 2018
 */package com.seeyoui.kensite.bussiness.exam.examResult.service;
 
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.seeyoui.kensite.bussiness.exam.examResult.domain.ExamResult;
import com.seeyoui.kensite.bussiness.exam.examResult.persistence.ExamResultMapper;
import com.seeyoui.kensite.common.base.service.BaseService;
import com.seeyoui.kensite.common.exception.CRUDException;

/**
 * ExamResult
 * @author dico
 * @version 2.0
 * @since 1.0
 * @date 2018-01-08
 */

@Service
public class ExamResultService extends BaseService {
	
	@Autowired
	private ExamResultMapper examResultMapper;

	/**
	 * 根据ID查询单条数据
	 * @param id
	 * @return
	 * @throws CRUDException
	 */
	public ExamResult findOne(String id) throws CRUDException{
		return examResultMapper.findOne(id);
	}
	
	/**
	 * 根据用户ID和考试ID查询单条数据
	 * @param userId
	 * @param examId
	 * @return ExamResult
	 * @throws CRUDException
	 */
	public ExamResult findByUserIdAndExamId(String userId, String examId) throws CRUDException{
		ExamResult examResult = new ExamResult();
		examResult.setUserId(userId);
		examResult.setExamId(examId);
		return examResultMapper.findByUserIdAndExamId(examResult);
	}
	
	/**
	 * 根据考试ID查询列表
	 * @param examId
	 * @return List<ExamResult>
	 */
	public List<ExamResult> findByExamId(String examId) throws CRUDException{
		return examResultMapper.findByExamId(examId);
	}
	
	/**
	 * 查询数据集合
	 * @param examResult
	 * @return
	 * @throws CRUDException
	 */
	public List<ExamResult> findList(ExamResult examResult) throws CRUDException {
		return examResultMapper.findList(examResult);
	}
	
	/**
	 * 查询所有数据集合
	 * @param examResult
	 * @return
	 * @throws CRUDException
	 */
	public List<ExamResult> findAll(ExamResult examResult) throws CRUDException {
		return examResultMapper.findAll(examResult);
	}
	
	/**
	 * 查询数据总数
	 * @param examResult
	 * @return
	 * @throws CRUDException
	 */
	public int findTotal(ExamResult examResult) throws CRUDException {
		return examResultMapper.findTotal(examResult);
	}
	
	/**
	 * 查询数据总数排除当前数据
	 * @param examResult
	 * @return
	 * @throws CRUDException
	 */
	public int findExTotal(ExamResult examResult) throws CRUDException {
		return examResultMapper.findExTotal(examResult);
	}
	
	/**
	 * 数据新增
	 * @param examResult
	 * @throws CRUDException
	 */
	public void save(ExamResult examResult) throws CRUDException{
		examResult.preInsert();
		examResultMapper.save(examResult);
	}
	
	/**
	 * 初始化数据新增
	 * @param userId
	 * @param examId
	 * @throws CRUDException
	 */
	public ExamResult save(String userId, String examId) throws CRUDException{
		ExamResult examResult = new ExamResult();
		examResult.setUserId(userId);
		examResult.setExamId(examId);
		examResult.setStartTime(new Date());
		examResult.setMarking("0"); // 默认未评分
		examResult.preInsert();
		examResultMapper.save(examResult);
		return examResult;
	}
	
	/**
	 * 数据修改
	 * @param examResult
	 * @throws CRUDException
	 */
	public void update(ExamResult examResult) throws CRUDException{
		examResult.preUpdate();
		examResultMapper.update(examResult);			
	}
	
	/**
	 * 数据删除
	 * @param listId
	 * @throws CRUDException
	 */
	public void delete(List<String> listId) throws CRUDException {
		examResultMapper.delete(listId);
	}
	
	/**
	 * 数据假删除
	 * @param examResult
	 * @throws CRUDException
	 */
	public void remove(ExamResult examResult) throws CRUDException{
		examResult.preUpdate();
		examResultMapper.remove(examResult);			
	}
	
}